package com.gift.recommendation.modules.login.controller;

import com.gift.recommendation.Base.BaseResponse;
import com.gift.recommendation.config.TokenPass;
import com.gift.recommendation.modules.login.biz.LoginImpl;
import com.gift.recommendation.modules.login.dto.SendEmailReq;
import com.gift.recommendation.modules.login.dto.UserLoginReq;
import com.gift.recommendation.modules.login.dto.UserLoginRsp;
import com.gift.recommendation.modules.login.dto.UserRegisterReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zzh <2658137258@qq.com>
 * @date 2022/12/29
 */
@RestController
@RequestMapping("/gift/login")
@Api(tags = "登录接口")
@Validated
public class LoginController {

    @Autowired
    private LoginImpl login;

    @ApiOperation(value = "用户登录")
    @RequestMapping(path = "/login",method = RequestMethod.POST)
    @TokenPass
    public BaseResponse userLogin(@RequestBody UserLoginReq req){
        UserLoginRsp result = login.userLogin(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "用户注册")
    @RequestMapping(path = "/register",method = RequestMethod.POST)
    @TokenPass
    public BaseResponse userRegister(@RequestBody UserRegisterReq req){
        login.userRegister(req);
        return BaseResponse.success("注册成功");
    };

    @ApiOperation(value = "发送电子邮件")
    @RequestMapping(path = "/send-email",method = RequestMethod.POST)
    @TokenPass
    public BaseResponse verification(@RequestBody SendEmailReq req){
        login.sendEmail(req);
        return BaseResponse.success();
    };
}
